#!/user/bin/env python3
# -*- coding: utf-8 -*-
"""
--------------------------------------
    Author:     JiChao_Song
    Date  :     2021/11/28 下午6:42
    Desc  :
--------------------------------------
"""
from django.core.paginator import Paginator
from django.db import transaction
from django.urls import path
from django.utils.decorators import method_decorator
from django_http_log.common.request import BaseAPIView, MongoBaseAPIView
from django_http_log.common.response import SuccessResponse, SystemExceptionResponse, CommonResponse, \
    ParamsErrorResponse
from werkzeug.security import generate_password_hash

from common.data import nav_data
from common.decorator.token_decorator import isAuthentication, Authentication
from common.enums.person_enums import PersonRegisterStatusEnums, PersonLoginSuccessStatusEnum
from common.enums.response_enums import CommonResultEnums
from common.utils.hook_utils import get_ip_address, get_browser_info, get_location_address_by_ip
from common.utils.log_utils import logger
from common.utils.other_utils import get_time, queryDict
from common.utils.token_utils import AccessTokenUtil, RequestAuthTokenUtil
from person.dto.PersonLoginLogDto import PersonLoginLogAddDto
from person.models.person import Person, PersonRegisterHistory, PersonLoginLog
from person.serializers.person import PersonSerializer, PersonRegisterHistorySerializer, PersonListSerializer, \
    PersonLoginLogRecordSerializer, PersonInfoSerializer
from person.tasks import login_log_record_task
from platform_auth.settings import APIDOC_DECORATOR


class PersonBaseAPIView(BaseAPIView):
    Model = Person

    serializer_class = PersonSerializer

    exclude_fields = ['deleted', 'deleteTime', 'password']


class PersonLoginAPIView(PersonBaseAPIView):
    """
    @author:    JiChao_Song
    @desc:      用户名、密码登录
    @date:      2021/11/29 17:09
    """

    @transaction.atomic
    @APIDOC_DECORATOR.checkParams
    @APIDOC_DECORATOR.start
    @APIDOC_DECORATOR.ApiTag(value = 'user', desc = '用户管理')
    @APIDOC_DECORATOR.ApiOperation(method = 'POST', path = '/user/login', summary = '用户登录')
    @APIDOC_DECORATOR.ApiParams(value = 'username', require = True, type = 'string', desc = '用户名')
    @APIDOC_DECORATOR.ApiParams(value = 'password', require = True, type = 'string', desc = '密码')
    def post(self, request, *args, **kwargs):
        try:
            body: dict = request.data.copy()

            username, password = body.get('username'), body.get('password')
            queryset = self.Model.objects.filter(username = username, deleted = False)

            personLoginLogAddDto = PersonLoginLogAddDto()
            browser_info = get_browser_info(request)
            personLoginLogAddDto.os = browser_info.get('os')
            personLoginLogAddDto.browser = browser_info.get('browser')
            personLoginLogAddDto.device = browser_info.get('device')
            personLoginLogAddDto.ipaddr = get_ip_address(request)
            personLoginLogAddDto.loginLocation = get_location_address_by_ip(personLoginLogAddDto.ipaddr)
            personLoginLogAddDto.username = username
            personLoginLogAddDto.lastLoginTime = get_time()
            personLoginLogAddDto.token = ''

            # 1. 判断用户是否存在
            if queryset.count() == 0:
                personLoginLogAddDto.msg = CommonResultEnums.USER_NOT_EXIST_BY_USERNAME.message
                personLoginLogAddDto.status = PersonLoginSuccessStatusEnum.FAIL.key
                personLoginLogAddDto.creatorId = 0
                personLoginLogAddDto.creatorName = username
                login_log_record_task.delay(personLoginLogAddDto.__dict__)
                return CommonResponse(codeEnums = CommonResultEnums.USER_NOT_EXIST_BY_USERNAME)

            person = queryset.first()
            personLoginLogAddDto.creatorId = person.id
            personLoginLogAddDto.creatorName = username

            # 2. 校验密码
            flag = person.check_password(password)
            if not flag:
                logger.error(f'密码: {password}')
                personLoginLogAddDto.msg = CommonResultEnums.CHECK_PASSWORD_FAIL.message
                personLoginLogAddDto.status = PersonLoginSuccessStatusEnum.FAIL.key
                login_log_record_task.delay(personLoginLogAddDto.__dict__)
                return CommonResponse(codeEnums = CommonResultEnums.CHECK_PASSWORD_FAIL)

            # 3. 用户状态
            if not person.isActive:
                personLoginLogAddDto.msg = CommonResultEnums.USER_STATUS_IS_FALSE.message
                personLoginLogAddDto.status = PersonLoginSuccessStatusEnum.FAIL.key
                login_log_record_task.delay(personLoginLogAddDto.__dict__)
                return CommonResponse(codeEnums = CommonResultEnums.USER_STATUS_IS_FALSE)

            # 4. 判断用户是否用户项目权限
            personLists = queryDict(
                sql = f"SELECT T2.id FROM tprojectperson T1 "
                      f"INNER JOIN tproject T2 ON T2.id = T1.projectId "
                      f"AND T2.projectStatus IN {102, 103} AND T2.deleted = FALSE "
                      f"WHERE T1.personId = {person.id} AND T1.deleted = FALSE ORDER BY T2.createTime DESC")
            if not person.isSuper and len(personLists) == 0:
                personLoginLogAddDto.msg = CommonResultEnums.USER_PROJECT_PERMISSION_IS_FALSE.message
                personLoginLogAddDto.status = PersonLoginSuccessStatusEnum.FAIL.key
                login_log_record_task.delay(personLoginLogAddDto.__dict__)
                return CommonResponse(codeEnums = CommonResultEnums.USER_PROJECT_PERMISSION_IS_FALSE)

            with transaction.atomic():
                # 记录最后登陆时间
                person.lastLoginTime = get_time()

                person.save()

            # 生成token
            accessTokenUtil = AccessTokenUtil()
            token = accessTokenUtil.generate_token()
            serializer = self.serializer_class(person, exclude = self.exclude_fields)
            userInfo = serializer.data
            userInfo['userId'] = person.id
            userInfo['username'] = person.username
            userInfo['expire_time'] = accessTokenUtil.expire.strftime('%Y-%m-%d %H:%M:%S')
            userInfo['token'] = token

            # 存取token到redis缓存中
            AccessTokenUtil.save_token(token = token, userInfo = userInfo)

            personLoginLogAddDto.token = token
            personLoginLogAddDto.msg = '登陆成功'
            personLoginLogAddDto.status = PersonLoginSuccessStatusEnum.SUCCESS.key

            login_log_record_task.delay(personLoginLogAddDto.__dict__)

            return SuccessResponse(result = {
                'token': token,
                'userInfo': serializer.data
            })

        except Exception as e:
            logger.error(e)
            return SystemExceptionResponse()


class PersonInfoAPIView(PersonBaseAPIView):
    """
    @author:    JiChao_Song
    @desc:      通过token获取用户信息
    @date:      2021/11/29 20:36
    """

    exclude_fields = ['deleted', 'deleteTime', 'password']
    serializer_class = PersonInfoSerializer

    @APIDOC_DECORATOR.checkParams
    @APIDOC_DECORATOR.start
    @APIDOC_DECORATOR.ApiOperation(method = 'POST', path = '/user/info', summary = '用户信息')
    @APIDOC_DECORATOR.ApiTag(value = 'user', desc = '用户管理')
    @method_decorator(isAuthentication(flag = True))
    def post(self, request, *args, **kwargs):
        try:
            userId = RequestAuthTokenUtil(request = request).get_user_id()

            queryset = self.Model.objects.filter(id = userId, deleted = False)

            if queryset.count() == 0:
                logger.info(f'用户id: {userId}')
                return CommonResponse(codeEnums = CommonResultEnums.USER_NOT_EXIST_BY_USER_ID)

            serializer = self.serializer_class(queryset.first(), exclude = self.exclude_fields)
            data = dict(serializer.data)
            data['role'] = {
                "id": "admin",
                "name": "管理员",
                "describe": "拥有所有权限",
                "status": 1,
                "creatorId": "system",
                "createTime": 1497160610259,
                "deleted": 0,
                "permissions": [
                    {
                        "roleId": "admin",
                        "permissionId": "dashboard",
                        "permissionName": "仪表盘",
                        "actions": '[{"action":"add","defaultCheck":False,"describe":"新增"},{"action":"query","defaultCheck":False,"describe":"查询"},{"action":"get","defaultCheck":False,"describe":"详情"},{"action":"update","defaultCheck":False,"describe":"修改"},{"action":"delete","defaultCheck":False,"describe":"删除"}]',
                        "actionEntitySet": [
                            {
                                "action": "add",
                                "describe": "新增",
                                "defaultCheck": False
                            },
                            {
                                "action": "detail",
                                "describe": "详情",
                                "defaultCheck": False
                            },
                            {
                                "action": "query",
                                "describe": "查询",
                                "defaultCheck": False
                            },
                            {
                                "action": "reset",
                                "describe": "重置",
                                "defaultCheck": False
                            },
                            {
                                "action": "update",
                                "describe": "修改",
                                "defaultCheck": False
                            },
                            {
                                "action": "delete",
                                "describe": "删除",
                                "defaultCheck": False
                            }
                        ],
                        "actionList": None,
                        "dataAccess": None
                    },
                    {
                        "roleId": "admin",
                        "permissionId": 400,
                        "permissionName": "系统管理",
                        "actions": '[]',
                        "actionEntitySet": [

                        ],
                        "actionList": None,
                        "dataAccess": None
                    },
                    {
                        "roleId": "admin",
                        "permissionId": 400100,
                        "permissionName": "用户管理",
                        "actions": '[]',
                        "actionEntitySet": [
                            {
                                "action": "400100100",
                                "describe": "新增",
                                "defaultCheck": False
                            },
                            {
                                "action": "400100101",
                                "describe": "删除",
                                "defaultCheck": False
                            },
                            {
                                "action": "400100102",
                                "describe": "启用",
                                "defaultCheck": False
                            },
                            {
                                "action": "400100103",
                                "describe": "停用",
                                "defaultCheck": False
                            },
                            {
                                "action": "400100104",
                                "describe": "编辑",
                                "defaultCheck": False
                            },
                            {
                                "action": "400100105",
                                "describe": "重置密码",
                                "defaultCheck": False
                            },
                        ],
                        "actionList": None,
                        "dataAccess": None
                    },
                    {
                        "roleId": "admin",
                        "permissionId": 400101,
                        "permissionName": "角色管理",
                        "actions": '[]',
                        "actionEntitySet": [
                            {
                                "action": "400101100",
                                "describe": "新增",
                                "defaultCheck": False
                            },
                            {
                                "action": "400101101",
                                "describe": "编辑",
                                "defaultCheck": False
                            },
                            {
                                "action": "400101102",
                                "describe": "功能权限",
                                "defaultCheck": False
                            },
                            {
                                "action": "400101103",
                                "describe": "删除",
                                "defaultCheck": False
                            },
                            {
                                "action": "400101104",
                                "describe": "用户数量",
                                "defaultCheck": False
                            },
                        ],
                        "actionList": None,
                        "dataAccess": None
                    },
                    {
                        "roleId": "admin",
                        "permissionId": 400102,
                        "permissionName": "注册管理",
                        "actions": '[]',
                        "actionEntitySet": [
                            {
                                "action": "400102100",
                                "describe": "通过",
                                "defaultCheck": False
                            },
                            {
                                "action": "400102101",
                                "describe": "拒绝",
                                "defaultCheck": True
                            },
                        ],
                        "actionList": None,
                        "dataAccess": None
                    },
                    {
                        "roleId": "admin",
                        "permissionId": 400103,
                        "permissionName": "菜单管理",
                        "actions": '[]',
                        "actionEntitySet": [
                        ],
                        "actionList": None,
                        "dataAccess": None
                    }
                ]
            }
            return SuccessResponse(result = data)

        except Exception as e:
            logger.error(e)
            return SystemExceptionResponse()


class PersonListAPIView(PersonBaseAPIView):
    """
    @author:    JiChao_Song
    @desc:      用户列表
    @date:      2021/11/29 20:36
    """
    serializer_class = PersonListSerializer

    @APIDOC_DECORATOR.checkParams
    @APIDOC_DECORATOR.start
    @APIDOC_DECORATOR.ApiOperation(method = 'POST', path = '/user/list', summary = '用户列表')
    @APIDOC_DECORATOR.ApiTag(value = 'user', desc = '用户管理')
    @APIDOC_DECORATOR.ApiParams(value = 'pageSize', type = 'string', require = True, desc = '每页数量')
    @APIDOC_DECORATOR.ApiParams(value = 'pageIndex', type = 'string', require = True, desc = '页码')
    @method_decorator(isAuthentication(flag = True))
    def post(self, request, *args, **kwargs):
        try:
            pageIndex, pageSize = request.data.get('pageIndex'), request.data.get('pageSize')
            if len(self.search_fields) != 0:
                queryset = self.Model.objects.filter(**self.search_queryset(request), deleted = False)
            else:
                queryset = self.Model.objects.filter(deleted = False)

            serializer = self.get_serializer(queryset, many = True)
            pageData = Paginator(serializer.data, pageSize)
            data = {
                'pageCount': pageData.count,
                'pageIndex': pageIndex,
                'pageSize': pageSize,
                'list': pageData.page(pageIndex).object_list
            }

            return SuccessResponse(result = data)
        except Exception as e:
            logger.error(e)
            return SystemExceptionResponse()


class PersonLogoutAPIView(PersonBaseAPIView):
    """
    @author:    JiChao_Song
    @desc:      退出登陆并删除token
    @date:      2021/11/30 15:54
    """

    @transaction.atomic
    @APIDOC_DECORATOR.checkParams
    @APIDOC_DECORATOR.start
    @APIDOC_DECORATOR.ApiTag(value = 'user', desc = '用户管理')
    @APIDOC_DECORATOR.ApiOperation(method = 'POST', path = '/user/logout', summary = '用户退出')
    @method_decorator(isAuthentication(flag = True))
    def post(self, request, *args, **kwargs):
        try:

            RequestAuthTokenUtil(request = request).delete_token()
            return SuccessResponse()
        except Exception as e:
            logger.error(e)
            return SystemExceptionResponse()


class PersonRegisterAPIView(PersonBaseAPIView):
    """
    @author:    JiChao_Song
    @desc:      用户注册
    @date:      2021/12/31 15:10
    """
    serializer_class = PersonRegisterHistorySerializer

    @APIDOC_DECORATOR.checkParams
    @APIDOC_DECORATOR.start
    @APIDOC_DECORATOR.ApiTag(value = 'user', desc = '用户管理')
    @APIDOC_DECORATOR.ApiOperation(method = 'POST', path = '/user/register', summary = '用户注册')
    @APIDOC_DECORATOR.ApiParams(value = 'username', type = 'String', require = True, desc = '用户名')
    @APIDOC_DECORATOR.ApiParams(value = 'password', type = 'String', require = True, desc = '用户密码')
    @APIDOC_DECORATOR.ApiParams(value = 'realName', type = 'String', require = True, desc = '姓名')
    @APIDOC_DECORATOR.ApiParams(value = 'phone', type = 'String', desc = '手机号')
    @APIDOC_DECORATOR.ApiParams(value = 'email', type = 'String', desc = '邮箱')
    def post(self, request, *args, **kwargs):
        try:
            body: dict = request.data.copy()
            username, password, realName = body.get('username'), body.get('password'), body.get('realName')
            phone, email = body.get('phone'), body.get('email')
            queryset = self.Model.objects.filter(username = username, deleted = False)

            if queryset.count() != 0:
                return CommonResponse(codeEnums = CommonResultEnums.USERNAME_IS_EXIST)

            if phone and phone != '':

                queryset_phone = self.Model.objects.filter(phone = phone, deleted = False)

                if queryset_phone.count() != 0:
                    return CommonResponse(codeEnums = CommonResultEnums.PHONE_IS_USED)

            if email and email != '':

                queryset_email = self.Model.objects.filter(email = email, deleted = False)
                if queryset_email.count() != 0:
                    return CommonResponse(codeEnums = CommonResultEnums.EMAIL_IS_USED)

            data = {
                'username': username,
                'password': generate_password_hash(password),
                'realName': realName,
                'phone': phone,
                'email': email
            }
            serializer = PersonRegisterHistorySerializer(data = data)
            if not serializer.is_valid():
                logger.error(f'注册用户失败--{serializer.errors}')
                return ParamsErrorResponse(message = serializer.errors, code = 40002)
            # 事务回滚
            with transaction.atomic():
                self.preform_create(serializer)

            return SuccessResponse(result = serializer.data)

        except Exception as e:
            logger.error(e)
            return SystemExceptionResponse()


class PersonRegisterListAPIView(PersonBaseAPIView):
    """
    @author:    JiChao_Song
    @desc:      用户注册待审核列表
    @date:      2021/12/31 15:11
    """
    serializer_class = PersonRegisterHistorySerializer
    Model = PersonRegisterHistory
    search_fields = ['-phone', 'username']

    @APIDOC_DECORATOR.checkParams
    @APIDOC_DECORATOR.start
    @APIDOC_DECORATOR.ApiTag(value = 'user', desc = '用户管理')
    @APIDOC_DECORATOR.ApiOperation(method = 'POST', path = '/user/registerList', summary = '用户注册列表')
    @APIDOC_DECORATOR.ApiParams(value = 'pageIndex', type = 'int', require = True, desc = '页码')
    @APIDOC_DECORATOR.ApiParams(value = 'pageSize', type = 'int', require = True, desc = '每页数量')
    @APIDOC_DECORATOR.ApiParams(value = 'username', type = 'String', desc = '用户名')
    @APIDOC_DECORATOR.ApiParams(value = 'phone', type = 'String', desc = '手机号')
    @method_decorator(isAuthentication(flag = True))
    def post(self, request, *args, **kwargs):
        try:
            pageIndex, pageSize = request.data.get('pageIndex'), request.data.get('pageSize')
            if len(self.search_fields) != 0:
                queryset = self.Model.objects.filter(**self.search_queryset(request),
                                                     registerStatus = PersonRegisterStatusEnums.REGISTERING.key,
                                                     deleted = False)
            else:
                queryset = self.Model.objects.filter(registerStatus = PersonRegisterStatusEnums.REGISTERING.key,
                                                     deleted = False)

            serializer = self.get_serializer(queryset, many = True, exclude = self.exclude_fields)
            pageData = Paginator(serializer.data, pageSize)
            data = {
                'pageCount': pageData.count,
                'pageIndex': pageIndex,
                'pageSize': pageSize,
                'list': pageData.page(pageIndex).object_list
            }
            return SuccessResponse(result = data)

        except Exception as e:
            logger.error(e)
            return SystemExceptionResponse()


class PersonRegisterExamineAPIView(PersonBaseAPIView):
    """
    @author:    JiChao_Song
    @desc:      用户注册审核通过或者拒绝
    @date:      2021/12/31 15:12
    """

    @APIDOC_DECORATOR.checkParams
    @APIDOC_DECORATOR.start
    @APIDOC_DECORATOR.ApiTag(value = 'user', desc = '用户管理')
    @APIDOC_DECORATOR.ApiOperation(method = 'POST', path = '/user/examine', summary = '注册用户审核')
    @APIDOC_DECORATOR.ApiParams(value = 'type', type = 'int', require = True, desc = '审核类型', remark = '#101 通过 #102 拒绝')
    @APIDOC_DECORATOR.ApiParams(value = 'personId', type = 'String', require = True, desc = '用户id(注册表)')
    def post(self, request, *args, **kwargs):
        try:
            body = request.data.copy()
            userId, userName = RequestAuthTokenUtil(request = request).get_user_id_and_username()
            personId, type = body.get('personId'), int(body.get('type'))
            if type not in [101, 102]:
                return ParamsErrorResponse(message = 'type参数不合法')

            # 查询注册中的用户
            personRegister = PersonRegisterHistory.objects.filter(id = personId, deleted = False,
                                                                  registerStatus = PersonRegisterStatusEnums.REGISTERING.key)

            if personRegister.count() == 0:
                return CommonResponse(codeEnums = CommonResultEnums.PERSON_REGISTER_ID_NOT_EXIST)
            p = personRegister.first()

            if type == 102:
                p.registerStatus = PersonRegisterStatusEnums.REGISTER_FAIL.key
                p.updateTime = get_time()
                p.updaterId = userId
                p.updaterName = userName
                with transaction.atomic():
                    p.save()
                return SuccessResponse()

            if type == 101:
                person = self.Model.objects.filter(username = p.username, deleted = False)
                if person.count() != 0:
                    return CommonResponse(codeEnums = CommonResultEnums.USERNAME_IS_EXIST)
                else:
                    p.registerStatus = PersonRegisterStatusEnums.REGISTER_SUCCESS.key
                    p.updateTime = get_time()
                    p.updaterId = userId
                    p.updaterName = userName
                    with transaction.atomic():
                        # 用户表插入数据
                        self.Model.objects.create(
                            username = p.username,
                            password = p.password,
                            realName = p.realName,
                            phone = p.phone,
                            email = p.email,
                            gender = p.gender,
                            avatar = p.avatar,
                            isActive = True,
                            creatorId = userId,
                            creatorName = userName,
                            createTime = get_time()
                        )
                        # 保存注册表修改
                        p.save()
                    return SuccessResponse()

        except Exception as e:
            logger.error(e)
            return SystemExceptionResponse()


class PersonNavAPIView(PersonBaseAPIView):
    @APIDOC_DECORATOR.checkParams
    @APIDOC_DECORATOR.start
    @APIDOC_DECORATOR.ApiTag(value = 'user', desc = '用户管理')
    @APIDOC_DECORATOR.ApiOperation(method = 'GET', path = '/user/nav', summary = '用户菜单列表')
    @method_decorator(isAuthentication(flag = True))
    def get(self, request, *args, **kwargs):
        data = nav_data
        return SuccessResponse(result = data)


class PersonStatusAPIView(PersonBaseAPIView):
    """
    @author:    JiChao_Song
    @desc:      启用、停用用户
    @date:      2021/12/31 15:12
    """

    @APIDOC_DECORATOR.checkParams
    @APIDOC_DECORATOR.start
    @APIDOC_DECORATOR.ApiTag(value = 'user', desc = '用户管理')
    @APIDOC_DECORATOR.ApiOperation(method = 'POST', path = '/user/status', summary = '用户状态')
    @APIDOC_DECORATOR.ApiParams(value = 'personId', type = 'String', require = True, desc = '用户id')
    @APIDOC_DECORATOR.ApiParams(value = 'status', type = 'Bool', require = True, desc = '用户状态')
    @method_decorator(isAuthentication(flag = True))
    def post(self, request, *args, **kwargs):
        try:
            body = request.data.copy()
            personId, status = body.get('personId'), body.get('status')
            modifyId, modifyName = RequestAuthTokenUtil(request = request).get_user_id_and_username()

            queryset = self.Model.objects.filter(id = personId, deleted = False)

            if queryset.count() == 0:
                return CommonResponse(codeEnums = CommonResultEnums.USER_NOT_EXIST_BY_USER_ID)

            person = queryset.first()

            person.isActive = status
            person.updaterId = modifyId
            person.updaterId = modifyName
            person.updateTime = get_time()

            with transaction.atomic():
                # 更新用户表
                person.save()

            return SuccessResponse()
        except Exception as e:
            logger.error(e)
            return SystemExceptionResponse()


class PersonArrayAPIView(PersonBaseAPIView):
    @APIDOC_DECORATOR.checkParams
    @APIDOC_DECORATOR.start
    @APIDOC_DECORATOR.ApiTag(value = 'user', desc = '用户管理')
    @APIDOC_DECORATOR.ApiOperation(method = 'POST', path = '/user/array', summary = '用户列表(全部)')
    @Authentication(isProject = False)
    def post(self, request, *args, **kwargs):
        try:

            queryset = self.Model.objects.filter(deleted = False)

            serializer = self.get_serializer(queryset, many = True, exclude = self.exclude_fields)

            return SuccessResponse(result = serializer.data)

        except Exception as e:

            logger.error(e)

            return SystemExceptionResponse()


class PersonLoginLogRecordAPIView(MongoBaseAPIView):
    serializer_class = PersonLoginLogRecordSerializer
    exclude_fields = ['deleted', 'deleteTime']

    @APIDOC_DECORATOR.checkParams
    @APIDOC_DECORATOR.start
    @APIDOC_DECORATOR.ApiTag(value = 'user', desc = '用户管理')
    @APIDOC_DECORATOR.ApiOperation(method = 'POST', path = '/user/loginRecord', summary = '用户登陆日志')
    @Authentication(isProject = False, flag = False)
    def post(self, request, *args, **kwargs):
        try:

            queryset = PersonLoginLog.objects.filter(deleted = False)

            serializer = self.get_serializer(queryset, many = True, exclude = self.exclude_fields)

            return SuccessResponse(result = serializer.data)

        except Exception as e:

            logger.error(e)

            return SystemExceptionResponse()


urlpatterns = [
    path('login', PersonLoginAPIView.as_view()),
    path('logout', PersonLogoutAPIView.as_view()),
    path('info', PersonInfoAPIView.as_view()),
    path('list', PersonListAPIView.as_view()),
    path('register', PersonRegisterAPIView.as_view()),
    path('registerList', PersonRegisterListAPIView.as_view()),
    path('examine', PersonRegisterExamineAPIView.as_view()),
    path('nav', PersonNavAPIView.as_view()),
    path('status', PersonStatusAPIView.as_view()),
    path('array', PersonArrayAPIView.as_view()),
    path('loginRecord', PersonLoginLogRecordAPIView.as_view()),
]
